package com.small;

import android.app.Activity;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.small.act.DiscountHomeActivity;
import com.small.act.UserCentreActivity;
import com.small.view.Home_listAda;
import com.smell.R;

public class HomeActivity extends Activity {

	ListView list_view;
	Home_listAda ada;
	private Vibrator mVibrator01 = null;
	private LocationClient mLocClient;
	TextView mTv;
	TextView	mTitle;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home_view);
		list_view = (ListView) this.findViewById(R.id.home_list);
		ada = new Home_listAda(this);
		list_view.setAdapter(ada);
		list_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				switch (arg2) {
				case 0:
					Intent idz = new Intent(HomeActivity.this,
							DzHomeActivity.class);
					HomeActivity.this.startActivity(idz);
					break;
				case 1:
					Intent iYhq = new Intent(HomeActivity.this,
							DiscountHomeActivity.class);
					HomeActivity.this.startActivity(iYhq);
					break;
				case 2:

					break;
				case 3:

					HomeActivity.this.startActivity(new Intent(
							HomeActivity.this, UserCentreActivity.class));
					break;
				}
			}
		});
		mTv = (TextView) findViewById(R.id.tv_location);
		mTitle = (TextView) findViewById(R.id.tv_cityName);
		mLocClient = ((MyApp) getApplication()).mLocationClient;
		((MyApp) getApplication()).mTv = mTv;
		mVibrator01 = (Vibrator) getApplication().getSystemService(Service.VIBRATOR_SERVICE);
		((MyApp) getApplication()).mVibrator01 = mVibrator01;
		setLocationOption(); 
		mLocClient.start();
//		if (!mIsStart) {
//			setLocationOption();
//			mLocClient.start();
//			// mStartBtn.setText("停止");
//			mIsStart = true;
//
//		} else {
//			mLocClient.stop();
//			mIsStart = false;
//			// mStartBtn.setText("开始");
//		}
	}

	private void setLocationOption() {
		LocationClientOption option = new LocationClientOption();
		option.setOpenGps(true); // 打开gps
		option.setCoorType("bd09ll"); // 设置坐标类型
		option.setServiceName("com.baidu.location.service_v2.9");
		option.setPoiExtraInfo(true);

		option.setAddrType("all");
		option.setScanSpan(10000);// 设置定位模式，小于1秒则一次定位;大于等于1秒则定时定位

		// option.setPriority(LocationClientOption.NetWorkFirst); // 设置网络优先

		option.setPriority(LocationClientOption.GpsFirst); // 不设置，默认是gps优先
		// }

		option.setPoiNumber(10);
		option.disableCache(true);
		mLocClient.setLocOption(option);
	}

	@Override
	public void onDestroy() {
		mLocClient.stop();
		((MyApp) getApplication()).mTv = null;
		super.onDestroy();
	}
} 